﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Oracle;

namespace card
{
    public partial class Frm_color : Form
    {
        public static WebDG.Service ws = new card.WebDG.Service();

        public static OracleDatabase db =
           new OracleDatabase("Data Source=sjzx;User ID=dbcenter;Password=ok;Unicode=True;Load Balance Timeout=1000");

        public Frm_color()
        {
            InitializeComponent();
        }

        private void Frm_color_Load(object sender, EventArgs e)
        {
            refresh_list();
        }

        private void refresh_list()
        { 
            listBox1.Items.Clear();
            string sqlStr = "select color from truck_color";
            DataSet ds = ws.getDataSet_Serv(sqlStr);
            //DataTable dt2 = db.ExecuteDataSet(db.GetSqlStringCommand(sqlStr.ToString())).Tables[0];
            //DataSet ds = db.ExecuteDataSet(db.GetSqlStringCommand(sqlStr.ToString()));
            //listBox1.DataSource = ds;
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    listBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
                MessageBox.Show("请输入要新增的颜色！");
                textBox1.Focus();
                return;
            }

            string StrSql1 = "insert into truck_color(color) values ('" + textBox1 .Text .Trim () + "')";
            //MessageBox.Show(StrSql);
            int ret1 = ws.execute_UID_Serv(StrSql1);
            //int ret1 = db.ExecuteNonQuery(db.GetSqlStringCommand(StrSql1.ToString()));
            if (ret1 == 1)
            {
                MessageBox.Show("更新数据库成功。");
            }
            else
            {
                MessageBox.Show("更新数据库失败。");
            }
            refresh_list();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem ==null )
            {
                MessageBox.Show("请选择要删除的颜色！");
                listBox1.Focus();
                return;
            }

            string StrSql1 = "delete from truck_color where color='" + listBox1 .SelectedItem .ToString () + "'";
            //MessageBox.Show(StrSql);
            int ret1 = ws.execute_UID_Serv(StrSql1);
            //int ret1 = db.ExecuteNonQuery(db.GetSqlStringCommand(StrSql1.ToString()));
            if (ret1 == 1)
            {
                MessageBox.Show("更新数据库成功。");
            }
            else
            {
                MessageBox.Show("更新数据库失败。");
            }
            refresh_list();
        }
    }
}
